package com.hgxd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hgxd.annotation.OperationLogAnnotation;
import com.hgxd.entity.vo.pagevo.RobotListPo;
import com.hgxd.result.Result;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import com.hgxd.service.IRobotListService;
import com.hgxd.entity.RobotList;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 机器人表 前端控制器
 * </p>
 *
 * @author wtf
 * @since 2023-12-01
 */
@Api(tags = "机器人表")
@RestController
@RequestMapping("/api/robot-list")
public class RobotListController {
    @Resource(name = "RobotListServiceImpl")
    private IRobotListService robotListService;
    /**
     * 根据组织查询下面的机器人
     */
    @PostMapping("/getRobotByOrganization/{organizationName}")
    @ApiOperation(value = "根据组织查询下面的机器人", notes = "传组织名称")
    @ApiImplicitParam(name = "organizationName", value = "组织名称")
    @OperationLogAnnotation(operModule = "机器人表-根据组织查询下面的机器人", operType = "查询", operContent = "根据组织查询下面的机器人")
public Result<List<RobotList>> getRobotByOrganization(@PathVariable String organizationName){
        return Result.ok(robotListService.getRobotByOrganization(organizationName));
    }
    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增", notes = "无需传入id")
    @ApiImplicitParam(name = "robotList", value = "实体类")
    @OperationLogAnnotation(operModule = "机器人表-新增", operType = "新增", operContent = "新增")
    public Result<Boolean> insert(@RequestBody RobotList robotList) {
        robotList.setUpdateTime(LocalDateTime.now());
        return Result.ok(robotListService.save(robotList));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改", notes = "必须传入id")
    @ApiImplicitParam(name = "robotList", value = "实体类")
    @OperationLogAnnotation(operModule = "机器人表-修改", operType = "修改", operContent = "修改")
    public Result<Boolean> update(@RequestBody RobotList robotList) {
        robotList.setUpdateTime(LocalDateTime.now());
        return Result.ok(robotListService.updateById(robotList));
    }

    /**
     * 根据id删除
     */
    @PostMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除", notes = "必须传入id")
    @ApiImplicitParam(name = "id", value = "id")
    @OperationLogAnnotation(operModule = "机器人表-根据id删除", operType = "删除", operContent = "根据id删除")
    public Result<Boolean> delete(@PathVariable Integer id) {
        return Result.ok(robotListService.removeById(id));
    }

    /**
     * 批量删除
     */
    @PostMapping("/del/batch")
    @ApiOperation(value = "批量删除", notes = "传入ids")
    @ApiImplicitParam(name = "ids", value = "id的数组")
    @OperationLogAnnotation(operModule = "机器人表-批量删除", operType = "删除", operContent = "批量删除")
    public Result<Boolean> deleteBatch(@RequestBody List<Integer> ids) {
        return Result.ok(robotListService.removeByIds(ids));
    }

    /**
     * 分页模糊查询
     */
    @PostMapping("/get/page")
    @ApiOperation(value = "分页模糊查询", notes = "传入对应所需参数")
    @ApiImplicitParam(name = "robotListPo", value = "分页工具类")
    @OperationLogAnnotation(operModule = "机器人表-分页模糊查询", operType = "查询", operContent = "分页模糊查询")
    public Result<Page<RobotList>> findPage(@RequestBody RobotListPo robotListPo) {
        LambdaQueryWrapper<RobotList> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(!"".equals(robotListPo.getOrganizationName()),RobotList::getOrganizationName,robotListPo.getOrganizationName())
                .eq(!"".equals(robotListPo.getStatu()),RobotList::getStatu,robotListPo.getStatu())
                .eq(!"".equals(robotListPo.getName()),RobotList::getName,robotListPo.getName());
        return Result.ok(robotListService.page(new Page<>(robotListPo.getPageNum(), robotListPo.getPageSize()), lambdaQueryWrapper));
    }
}

